package com.wwj.utils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * Created by xya on 17-3-2.
 */
public class RandomUtils {

    public static List<Integer> nextInt(int total, int num, int min) {
        List<Integer> result = new ArrayList<Integer>(num);
        for (int i = 0; i < num; i++) {
            int r;
            if (i != num - 1) {
                do {
                    r = org.apache.commons.lang.math.RandomUtils.nextInt(total);
                } while (r < min || !(r != total && total - r > (num - i) * min));
            } else {
                r = total;
            }
            result.add(r);
            total -= r;
        }
        Collections.shuffle(result);
        return result;
    }

    public static void main(String[] args) {
        for (int i=0;i<5;i++)
        System.out.println(nextInt(1000, 6, 1));
    }

}
